#!/usr/bin/php
<?php
if (sizeof($argv) <2 || sizeof($argv) > 2) {
	echo "$argv[0] [temp_sensor_number]\n";
	exit;
}
if (!is_numeric($argv[1])) {
	echo "$argv[0] [temp_sensor_number]\n";
	exit;
}
$OK = false;
$lines = file("/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves");
for ($i = 0;$i<sizeof($lines); $i++) {
	$lines[$i] = trim($lines[$i]);
	$o = $i;
	$o++;
	if ($o == $argv[1]) {
		//echo $lines[$i] ."\n";
                $reading = file("/sys/bus/w1/devices/".$lines[$i]."/w1_slave");
                foreach($reading as $r) {
                        $r = trim($r);
                        if ($OK) {
                                $temp = explode("=",$r);
                                $temp = $temp[1];
                                $temp = $temp/1000;
                                $temp = ($temp*1.8000)+32.00;
                                $temp = round($temp,2);
				echo $temp ."\n";				
			}
                        if (strstr($r,"YES") && $OK==false) {
                                $OK = true;
                                //echo $r ."\n";
                        }  
		}
	}
}
?>
